package com.itheima.api.collection.demo01;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class CollectionDemo {

    public static void main(String[] args) {

        Collection<String> collection = new ArrayList<String>();

        collection.add("hello");
        collection.add("hell");
        collection.add("hel");
        collection.add("he");

        System.out.println(collection);
        System.out.println("----------------------");

        Iterator<String> iterator = collection.iterator();

        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("----------------------");

        for(String s : collection){
            System.out.println(s + " ");
        }
        System.out.println("----------------------");

        collection.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("----------------------");

        collection.forEach((String s) -> {
            System.out.println(s);
        });
        System.out.println("----------------------");

        String[] arr = {"萧忆情","舒靖容","迦若"};



        for(String s : arr){
            System.out.print(s + " ");
        }
    }
}
